package org.example.myerp.service.serviceimpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;




import org.example.myerp.mapper.UserMapper;
import org.example.myerp.pojo.*;
import org.example.myerp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public List<User> getUsers() {
		return userMapper.getUsers();
	}

	@Override
	public User login(String uname, String upwd) {
		// TODO Auto-generated method stub
		return userMapper.login(uname, upwd);
	}

	@Override
	public PageMyself<User> findByPager(Integer pageNum, Integer pageSize) {
		Map params = new HashMap<String, Object>();
		params.put("pageNum", pageNum);
		params.put("pageSize", pageSize);
		PageMyself<User> page = new PageMyself<User>();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		List<User> lis = userMapper.findByPager(params);
		page.setRows(lis);
		page.setTotal(userMapper.pageTotal());
		return page;
	}

	@Override
	public void addUser(User user) {
		userMapper.addUser(user);

	}

	@Override
	public void batchDelUser(Integer[] uids) {
       userMapper.batchDelUser(uids);
	}

	@Override
	public void updateUser(User user) {
	    userMapper.updateUser(user);
	}

	@Override
	public void updateStatics(Integer uid, String statics) {
		userMapper.updateStatics(uid, statics);

	}

	@Override
	public void setUserRole(Integer[] rid, Integer uid) {
		if (rid.length>0) {
			userMapper.delUserRole(uid);
			for (int i = 0; i < rid.length; i++) {
				userMapper.addUserRole(rid[i], uid);
			}
		}else {
			userMapper.delUserRole(uid);
		}

	}

}
